<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <pre>
var arr = [
    {id: 1,created: '2016-05-04 15:12:40',content: '1'},
    {id: 2,created: '2016-04-06 15:12:40',content: '2'},
    {id: 3,created: '2016-04-02 15:12:40',content: '3'},
]
将上面数据转换成下面数据格式
方式:(1)使用原生的js
(2)使用lodash
提示
思路:(1)思考转换成下面这种数据结果需要做哪些内容
        分组
        排序
        数据结构
(2)先做最简单内容
需要用到操作:
(1)数组map,sort
(2)lodash的map,group,链式调用
var map = [
    {month: '4月', data: [//(1)按月份分组,并且月份由小到大
        {id: 3,created: '2016-04-02 15:12:40',content: '3'},//(2)按时间排序,由远到近
        {id: 2,created: '2016-04-06 15:12:40',content: '2'}
    ]},
    {month: '5月', data: [
    {id: 1,created: '2016-05-04 15:12:40',content: '1'}
    ]}
]
    </pre>
</body>
<script>
    // var map = [
    //     {month: '4月', data: [ //(1)按月份分组,并且月份由小到大
    //         {id: 3,created: '2016-04-02 15:12:40',content: '3'}, //(2)按时间排序,由远到近
    //         {id: 2,created: '2016-04-06 15:12:40',content: '2'}
    //     ]},
    //     {month: '5月', data: [
    //     {id: 1,created: '2016-05-04 15:12:40',content: '1'}
    //     ]}
    // ]
08998
    var arr = [
        {id: 1,created: '2016-05-04 15:12:40',content: '1'},
        {id: 2,created: '2016-04-06 15:12:40',content: '2'},
        {id: 3,created: '2016-04-02 15:12:40',content: '3'},
        {id: 4,created: '2016-07-02 15:12:40',content: '4'},
        {id: 5,created: '2016-04-01 15:12:40',content: '5'},
    ]

    let newMon = [] // [5, 4]
    let data = arr.map(m => {
        newMon.push(new Date(m.created).getMonth() + 1)
        newMon = [...new Set(newMon)]
        m.aaa = new Date(m.created).getMonth() + 1
        return m
    })
    console.log(data);

    data.forEach(t => {
        newO = newMon.map(n => {
            return {month: n+'月', data: []}
        })
    })

    data.forEach(t => {
        newO.forEach(m => {
            if(m.month.slice(0,1)-0 === t.aaa){
                m.data.push({id: t.id, created: t.created, content: t.content})
            }
        })
    })
    newO.sort((a,b)=> (a.month.slice(0,1)-0) - (b.month.slice(0,1)-0))
    newO.forEach(t => {
        t.data.sort((a, b) => +new Date(a.created) - +new Date(b.created))
    })
    console.log(newO);
</script>

</html>
